

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/avatar.gif">
  <link rel="icon" href="/img/avatar.gif">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="马振东">
  <meta name="keywords" content="Java,计算机,数据结构">
  
    <meta name="description" content="一、索引定义：索引是帮助数据库高效获取数据的数据结构也可以简单理解为：&quot;排好序的快速查找数据结构&quot;">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL索引优化">
<meta property="og:url" content="https://bolg.plumdong.top/2020/11/21/MySQL%E7%B4%A2%E5%BC%95%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="PlumDong Bolg">
<meta property="og:description" content="一、索引定义：索引是帮助数据库高效获取数据的数据结构也可以简单理解为：&quot;排好序的快速查找数据结构&quot;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://bolg.plumdong.top/myimages/202011211309.png">
<meta property="article:published_time" content="2020-11-20T16:00:00.000Z">
<meta property="article:modified_time" content="2023-03-13T06:57:46.554Z">
<meta property="article:author" content="马振东">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://bolg.plumdong.top/myimages/202011211309.png">
  
  
  
  <title>MySQL索引优化 - PlumDong Bolg</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"bolg.plumdong.top","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="PlumDong Bolg" type="application/atom+xml">
</head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 60vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>PlumDong Bolg</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="MySQL索引优化"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2020-11-21 00:00" pubdate>
          2020年11月21日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          1.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          15 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">MySQL索引优化</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="一、索引定义："><a href="#一、索引定义：" class="headerlink" title="一、索引定义："></a>一、索引定义：</h1><p><strong>索引是帮助数据库高效获取数据的数据结构</strong></p>
<p>也可以简单理解为：”排好序的快速查找数据结构”</p>
<span id="more"></span>

<p>如下就是一种可能的索引实例：</p>
<p><img src="/myimages/202011211309.png" srcset="/img/loading.gif" lazyload alt="索引实例"></p>
<p>优势：</p>
<ul>
<li>提高数据检索的效率， 降低数据库的IO成本。</li>
<li>通过索引列对数据进行排序， 降低数据排序的成本， 降低了CPU的消耗。</li>
</ul>
<p>劣势：</p>
<ul>
<li>虽然索引大大提高了查询速度， 同时却会降低更新表的速度， 如对表进行INSERT、 UPDATE和DELETE。 因为<br>更新表时， MySQL不仅要保存数据， 还要保存一下索引文件每次更新添加了索引列的字段， 都会调整因为<br>更新所带来的键值变化后的索引信息。</li>
<li>实际上索引也是一张表， 该表保存了主键与索引字段， 并指向实体表的记录， 所以索引列也是要占用空间<br>的。</li>
</ul>
<h1 id="二-、创建和删除索引"><a href="#二-、创建和删除索引" class="headerlink" title="二 、创建和删除索引"></a>二 、创建和删除索引</h1><h2 id="1-创建索引"><a href="#1-创建索引" class="headerlink" title="1.创建索引"></a>1.创建索引</h2><p>方法一、</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name <span class="hljs-keyword">ADD</span> INDEX index_name (column1,column2,column3)<br></code></pre></td></tr></table></figure>
<p>方法二、</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">create</span> index index_name <span class="hljs-keyword">on</span> table_name(column1,column2,column3);<br></code></pre></td></tr></table></figure>
<p>单值索引： 即一个索引只包含单个列， 一个表可以有多个单列索引</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> INDEX index_name <span class="hljs-keyword">ON</span> table_name(column_name);<br></code></pre></td></tr></table></figure>
<p>唯一索引 ：索引列的值必须唯一， 但允许有空值</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">UNIQUE</span> INDEX index_name <span class="hljs-keyword">ON</span> table_name(column_name);<br></code></pre></td></tr></table></figure>
<p>主键索引 ：<br>设定为主键后数据库会自动建立索引</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs sql">主键索引创建<br><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name <span class="hljs-keyword">add</span> <span class="hljs-keyword">PRIMARY</span> KEY table_name(column_name)<br>主键索引删除<br><span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> table_name <span class="hljs-keyword">drop</span> <span class="hljs-keyword">PRIMARY</span> KEY ;<br></code></pre></td></tr></table></figure>
<p>复合索引 ：即一个索引包含多个列</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> INDEX index_name <span class="hljs-keyword">ON</span> table_name(column1,column2);<br></code></pre></td></tr></table></figure>

<h2 id="2-删除索引"><a href="#2-删除索引" class="headerlink" title="2.删除索引"></a>2.删除索引</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">DROP</span> INDEX indexName <span class="hljs-keyword">ON</span> table_name<br></code></pre></td></tr></table></figure>
<h2 id="3-查看表的索引"><a href="#3-查看表的索引" class="headerlink" title="3.查看表的索引"></a>3.查看表的索引</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">SHOW</span> INDEX <span class="hljs-keyword">FROM</span> table_name;<br></code></pre></td></tr></table></figure>
<h1 id="三-、索引的创建时机"><a href="#三-、索引的创建时机" class="headerlink" title="三 、索引的创建时机"></a>三 、索引的创建时机</h1><h2 id="需要创建索引的情况"><a href="#需要创建索引的情况" class="headerlink" title="需要创建索引的情况"></a>需要创建索引的情况</h2><ol>
<li>主键自动建立唯一索引</li>
<li>频繁作为查询条件的字段应该创建索引</li>
<li>查询中与其他表关联的字段，外键关系建立索引</li>
<li>在高并发下倾向创建组合索引</li>
<li>查询中排序的字段，排序字段若通过索引去访问将大大提高排序速度</li>
</ol>
<h2 id="不需要创建索引的情况"><a href="#不需要创建索引的情况" class="headerlink" title="不需要创建索引的情况"></a>不需要创建索引的情况</h2><ol>
<li>数据量较少，一般数据量要大于100万MySQL性能才会有明显的下降</li>
<li>不常用的列,若建立索引会增大空间需求，实用性不高；</li>
<li>数据表操作（增、删、改）远大于查询时不建议创建索引。</li>
<li>不要为重复过多的数据列建立索引，例如性别列</li>
</ol>
<h1 id="四、查询优化"><a href="#四、查询优化" class="headerlink" title="四、查询优化"></a>四、查询优化</h1><h2 id="1-最佳左前缀法则"><a href="#1-最佳左前缀法则" class="headerlink" title="1. 最佳左前缀法则"></a>1. 最佳左前缀法则</h2><ul>
<li>最佳左前缀指的是查询从索引的最左前列开始并且不跳过索引中的列。</li>
<li>使用复合索引， 需要遵循最佳左前缀法则， 即如果索引了多列， 要遵守最左前缀法则。 </li>
<li>过滤条件要使用索引必须按照索引建立时的顺序， 依次满足， 一旦跳过某个字段， 索引后面的字段都无法被使用。</li>
</ul>
<h2 id="2-不要在索引列上做任何计算"><a href="#2-不要在索引列上做任何计算" class="headerlink" title="2. 不要在索引列上做任何计算"></a>2. 不要在索引列上做任何计算</h2><ul>
<li>不在索引列上做任何操作（计算、 函数、 (自动 or 手动)类型转换）， 会导致索引失效而转向全表扫描。</li>
</ul>
<h2 id="3-索引列上尽量减少范围查询"><a href="#3-索引列上尽量减少范围查询" class="headerlink" title="3. 索引列上尽量减少范围查询"></a>3. 索引列上尽量减少范围查询</h2><ul>
<li>将可能做范围查询的字段的索引顺序放在最后</li>
</ul>
<h2 id="4-尽量使用覆盖索引"><a href="#4-尽量使用覆盖索引" class="headerlink" title="4. 尽量使用覆盖索引"></a>4. 尽量使用覆盖索引</h2><ul>
<li>即查询列和索引列一致或少于索引列， 不要写 select *!</li>
</ul>
<h2 id="5-不要使用不等于-或者-lt-gt"><a href="#5-不要使用不等于-或者-lt-gt" class="headerlink" title="5. 不要使用不等于(!= 或者&lt;&gt;)"></a>5. 不要使用不等于(!= 或者&lt;&gt;)</h2><ul>
<li>mysql 在使用不等于(!= 或者&lt;&gt;)时， 有时会无法使用索引会导致全表扫描</li>
</ul>
<h2 id="6-使用-is-null-而非-is-not-null"><a href="#6-使用-is-null-而非-is-not-null" class="headerlink" title="6. 使用 is null  而非 is not null"></a>6. 使用 is null  而非 is not null</h2><ul>
<li>因为is not null 用不到索引， is null 可以用到索引。</li>
</ul>
<h2 id="8-like-的前后模糊匹配"><a href="#8-like-的前后模糊匹配" class="headerlink" title="8. like 的前后模糊匹配"></a>8. like 的前后模糊匹配</h2><ul>
<li>前缀不能出现模糊匹配！</li>
<li>like 条件匹配时’chen%’和’chen%j%’可以用到索引,like ‘%chen’和’%chen%’用不到索引</li>
<li>如果非要写’%chen%’要尽量使用覆盖索引，即查询列与索引列一致或少于索引列</li>
</ul>
<h2 id="9-减少使用-or"><a href="#9-减少使用-or" class="headerlink" title="9. 减少使用 or"></a>9. 减少使用 or</h2><ul>
<li>使用 union all 或者 union 来替代：</li>
</ul>
<h1 id="五、排序优化"><a href="#五、排序优化" class="headerlink" title="五、排序优化"></a>五、排序优化</h1><h2 id="1-尽量在索引列上完成排序"><a href="#1-尽量在索引列上完成排序" class="headerlink" title="1. 尽量在索引列上完成排序"></a>1. 尽量在索引列上完成排序</h2><h2 id="2-避免使用select-，只查询需要的列"><a href="#2-避免使用select-，只查询需要的列" class="headerlink" title="2. 避免使用select *，只查询需要的列"></a>2. 避免使用select *，只查询需要的列</h2><h2 id="3-最佳左前缀法则"><a href="#3-最佳左前缀法则" class="headerlink" title="3. 最佳左前缀法则"></a>3. 最佳左前缀法则</h2><ul>
<li>若最索引在where种变为常量，则可变为次前缀<h2 id="4-增大MySQL参数sort-buffer-size，增大排序缓冲区"><a href="#4-增大MySQL参数sort-buffer-size，增大排序缓冲区" class="headerlink" title="4. 增大MySQL参数sort_buffer_size，增大排序缓冲区"></a>4. 增大MySQL参数sort_buffer_size，增大排序缓冲区</h2></li>
</ul>
<h1 id="六、-分组优化"><a href="#六、-分组优化" class="headerlink" title="六、 分组优化"></a>六、 分组优化</h1><h2 id="1-group-by实质是先排序后分组，遵循最佳左前缀"><a href="#1-group-by实质是先排序后分组，遵循最佳左前缀" class="headerlink" title="1. group by实质是先排序后分组，遵循最佳左前缀"></a>1. group by实质是先排序后分组，遵循最佳左前缀</h2><h2 id="2-where高于having，能在where中限定的条件不要去having中限定"><a href="#2-where高于having，能在where中限定的条件不要去having中限定" class="headerlink" title="2. where高于having，能在where中限定的条件不要去having中限定"></a>2. where高于having，能在where中限定的条件不要去having中限定</h2>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/MySQL/" class="category-chain-item">MySQL</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/MySQL/">#MySQL</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>MySQL索引优化</div>
      <div>https://bolg.plumdong.top/2020/11/21/MySQL索引优化/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>马振东</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2020年11月21日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/11/22/MySQL%E9%94%81%E6%9C%BA%E5%88%B6/" title="MySQL锁机制">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">MySQL锁机制</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/11/21/%E9%B8%A1%E8%9B%8B%E6%8E%89%E8%90%BD-%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/" title="鸡蛋掉落——动态规划">
                        <span class="hidden-mobile">鸡蛋掉落——动态规划</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
